package cn.factorybox.common.utils;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-04-07 11:43
 */
public class DateFormatUtil {

    public static Date changeDate(String time) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
        return simpleDateFormat.parse(time);
    }

    public static String formatDate(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateTime = sdf.format(date);
        return dateTime;
    }

    public static String formatTime(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        String time = sdf.format(date);
        return time;
    }

    public static String formatDeviceTime(Object object){
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
        Date date = (Date) object;
        String time = sdf.format(date);
        return time;
    }

    public static Double formatDouble(Double data) {
        DecimalFormat df = new DecimalFormat("0.0");
        return Double.valueOf(df.format(data));
    }

    public static String formatDoubleToString1(Double data) {
        return String.format("%.1f",data);
    }

    public static String formatDoubleToString2(Double data) {
        return String.format("%.2f",data);
    }

    public static String formatDoubleToString3(Double data) {
        return String.format("%.3f",data);
    }
}
